package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.MaterialDto;
import com.heima.utils.common.AppJwtUtil;
import com.heima.wemedia.service.WmMaterialService;
import com.heima.wemedia.utils.Token;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwsHeader;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author 嘉德罗斯
 * @date 2021/11/22
 */
@RequestMapping("/api/v1/material")
@RestController
public class MaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody MaterialDto dto, HttpServletRequest request){
        Integer id = Token.getId(request);
        ResponseResult responseResult = wmMaterialService.find(dto,id);
        return responseResult;
    }

    @PostMapping("/upload_picture")
    public ResponseResult upload(MultipartFile multipartFile,HttpServletRequest request) throws IOException {
        Integer id = Token.getId(request);
        ResponseResult responseResult = wmMaterialService.upload(multipartFile,id);
        return responseResult;
    }

    @GetMapping("/del_picture/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        ResponseResult responseResult = wmMaterialService.delete(id);
        return responseResult;
    }

    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Integer id){
        ResponseResult responseResult = wmMaterialService.collect(id);
        return responseResult;
    }

    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancel(@PathVariable Integer id){
        ResponseResult responseResult = wmMaterialService.cancel(id);
        return responseResult;
    }
}
